<?php

// 获取上传凭据
// GET qiniu.token.upload

namespace app\api\resource\qiniu\token;
use app\qiniu\lib\UploadToken;

class Upload
{
    // 方法
    public $_method = ['GET'];
    // 前置
    public $_pre    = [];
    // 描述
    public $_description = '获取上传凭据';
    // 参数
    public $_param  = [
        'fileName' => '资源名称',
    ];
    // 返回
    public $_return = [
        200 => '请求成功',
        422 => '资源名称必须',
    ];

    public function run(&$request)
    {
        $fileName = $request->get('fileName/s','','trim');

        if ( empty($fileName) ) return [422,'资源名称必须'];

        $res['uptoken'] = UploadToken::get($fileName);

        return [200,$res];
    }
}